package com.xmy.cultivate.service.impl;

import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.xmy.cultivate.entity.Quarter;
import com.xmy.cultivate.entity.views.PassRade;
import com.xmy.cultivate.feign.english.IFeiEnglishFeignClient;
import com.xmy.cultivate.mapper.RoleAdminMapper;
import com.xmy.cultivate.respons.PlanShutNum;
import com.xmy.cultivate.service.IQuarterService;
import com.xmy.cultivate.service.IStudyPlanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class StudyPlanImpl implements IStudyPlanService {

    @Autowired
    @Lazy
    IQuarterService iQuarterService;

    @Autowired
    RoleAdminMapper roleAdminMapper;

    @Autowired
    IFeiEnglishFeignClient iFeiEnglishFeignClient;

    @Override
    public List<PassRade> getMinimumTaskProgressRateNew(Integer readingStatus, String schoolId, String yearPart, String yearClassId, Integer type, String classTypeId, String quarterNum, String gradeSection, Integer taskCourseNum, Integer taskCourseNumNow, String courseTypeId, String taskDateStart, String taskDateEnd,Integer tabsType,String include) {
        Quarter quarter = iQuarterService.getNowQuarter();
        if (StringUtils.isNotBlank(yearPart) && StringUtils.isNotBlank(quarterNum)) {
            quarter.setYearPart(Integer.parseInt(yearPart));
            quarter.setNum(Integer.parseInt(quarterNum));
        }

        PlanShutNum planShutNum = new PlanShutNum();

        planShutNum.setType(type);
        planShutNum.setSchoolId(schoolId);
        planShutNum.setReadingStatus(readingStatus);
        planShutNum.setQuarterNum(quarter.getNum());
        planShutNum.setYearPart(quarter.getYearPart());
        planShutNum.setClassTypeId(courseTypeId);
        planShutNum.setTaskCourseNum(taskCourseNum);//开始课次
        planShutNum.setTaskCourseNumNow(taskCourseNumNow);//结束课次
        planShutNum.setTaskDateStart(taskDateStart);//开始时间
        planShutNum.setTaskDateEnd(taskDateEnd);//结束时间
        planShutNum.setTabsType(tabsType);//1人数 2关数
        planShutNum.setInclude(include);//0三次课以内，1三次课以外

        if (type == 3) {
            List<Long> headmasterIdList = roleAdminMapper.getAdminIdListByRoleAdmin(1568160887369994242L);
            planShutNum.setHeadmasterIdList(headmasterIdList);
        }

        StringBuilder yearClassIdSb = new StringBuilder();
        if (gradeSection != null && !gradeSection.equals("")) {
            String[] sections = gradeSection.split(",");
            for (String section : sections) {
                if (section.equals("0")) {
                    yearClassIdSb.append("1,2");
                } else if (section.equals("1")) {
                    yearClassIdSb.append("3,4,5,6");
                } else if (section.equals("2")) {
                    yearClassIdSb.append("7,8,9");
                } else if (section.equals("3")) {
                    yearClassIdSb.append("10,11,12");
                }
                if (!section.equals(sections[sections.length - 1])) {
                    yearClassIdSb.append(",");
                }
            }
            yearClassId = yearClassIdSb.toString();
        }
        planShutNum.setYearClassId(yearClassId);

        List<PassRade> hashMapList = iFeiEnglishFeignClient.getMinimumTaskProgressRateEqualNew(planShutNum);

        return hashMapList;
    }
}
